package com.kool.kadmin.system.controller;

import com.kool.kadmin.common.bean.ListResult;
import com.kool.kadmin.common.bean.PageListResult;
import com.kool.kadmin.common.bean.Result;
import com.kool.kadmin.common.util.ResultUtil;
import com.kool.kadmin.system.bean.SysParamDo;
import com.kool.kadmin.system.request.AddParamReq;
import com.kool.kadmin.system.request.DeleteParamReq;
import com.kool.kadmin.system.request.GetParamPageReq;
import com.kool.kadmin.system.request.UpdateParamReq;
import com.kool.kadmin.system.service.ParamService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author luyu
 */
@RestController
public class ParamController {
    @Resource
    private ParamService paramService;

    /**
     * 增加
     *
     * @param request
     * @return
     */
    @RequestMapping("/sys/param/add")
    public Result add(@Valid @RequestBody AddParamReq request) {
        paramService.add(request);
        return ResultUtil.success();
    }

    /**
     * 查询所有
     *
     * @return
     */
    @RequestMapping("/sys/param/getAll")
    public ListResult<SysParamDo> getAll() {
        return paramService.getAll();
    }

    /**
     * 修改
     *
     * @param request
     * @return
     */
    @RequestMapping("/sys/param/update")
    public Result update(@Valid @RequestBody UpdateParamReq request) {
        paramService.updateById(request);
        return ResultUtil.success();
    }

    /**
     * 删除
     *
     * @param request
     * @return
     */
    @RequestMapping("/sys/param/delete")
    public Result delete(@Valid @RequestBody DeleteParamReq request) {
        paramService.deleteById(request.getId());
        return ResultUtil.success();
    }

    /**
     * 分页查询
     *
     * @param request
     * @return
     */
    @RequestMapping("/sys/param/getPage")
    public PageListResult<SysParamDo> getPage(@Valid @RequestBody GetParamPageReq request) {
        return paramService.getPage(request);
    }
}
